/*
 * @Author: ls
 * @Date: 2020-09-03 18:09:18
 * @LastEditTime: 2020-09-14 08:55:47
 * @LastEditors: Please set LastEditors
 * @Description: 引导类
 * @FilePath: \snake\assets\guideCtrl.js
 */

cc.Class({
    extends: cc.Component,

    properties: {
        step: [cc.Node],
        startToggle: cc.Toggle,
    },

    onLoad() {
        this.startGuide();
        this.startToggle.isChecked = false;
    },

    /**
     * 开始引导
     */
    startGuide() {
        if (!this.step.length) {
            this.node.destroy();
            return;
        }
        for (let index = 0, length = this.step.length; index < length; index++) {
            this.step[index].active = false;
        }
        this._step = 0;
        this.step[0].active = true;
    },

    /**
     * 下一个引导页面
     */
    nextGuide() {
        this._step++;
        if (this._step < this.step.length - 1) {
            this.step[this._step].active = true;
            this.step[this._step - 1].active = false;
            if (this._step === this.step.length - 2) {
                this.step[this._step + 1].active = true;
            }
        } else {
            this.node.active = false;
        }
    },

    callback: function (toggle) {
        cc.sys.localStorage.setItem('isStart', toggle.isChecked);
    },
});
